<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/19
 * Time: 12:28
 */
namespace app\boxing\controller;

use app\boxing\model\AdminRule;
use app\boxing\model\Adminuser;
use app\boxing\model\BbsCard;
use think\Cache;
use think\Cookie;
use think\Request;

class Rule extends BassController{

    /**
     * 权限列表
     */
    public function rule_list(){

        $rule_list = AdminRule::all();
        $rule_list = infinite($rule_list,0,0);

        return view('',['rule_list'=>$rule_list]);
    }

    /**
     * 权限修改和添加
     */
    public function rule(){
        if(\request()->isPost()){
            $data = \request()->post();
            if(empty($data['id'])){
                //添加
                $res = AdminRule::create($data);
            }else{
                //修改
                $obj = AdminRule::get($data['id']);
                $res = $obj->save($data);
            }
            if($res){
                return_json(1,'操作成功');
            }else{
                return_json(0,'操作失败');
            }
        }
        $id = intval(Request::instance()->param('id'));
        $one = AdminRule::where('id',$id)->find();
        $parent_rule = AdminRule::where('p_id',0)->field('id,title,status')->select();
        $result = [
            'one'=>$one,
            'parent_rule'=>$parent_rule
        ];
       return view('',['result'=>$result]);
    }
}